﻿Imports DotNetNuke.Light
Module Module1

    Sub Main()

        Dim p As New Proxy

        Dim request As New Common.Request
        Dim response As New Common.Response

        Dim val(0) As String
        val(0) = "1"
        'val(1) = "4567"
        request.Args = val

        request.Connection = New Common.Connection()
        request.Connection.Credential = New Common.Credential()
        request.Connection.Credential.UserName = "admin"
        request.Connection.Credential.Password = "password#1"
        request.Connection.Credential.PortalID = 0
        'request.MethodName = "Echo"
        request.MethodName = "GetUserInbox" ' "GetMessageByID" '"GetInboxCount" '"GetNewMessageCount" '"GetUserInbox"
        'request.Connection.Credential.UserName = DotNetNuke.Light.Common.Credential.AnonymousUser
        'request.Connection.Credential.Password = ""
        'request.Connection.Credential.PortalID = 0
        'request.MethodName = "EchoAnon"
        
        request.Connection.Server = New Common.Server
        request.Connection.Server.ServerUri = New System.Uri("http://localhost/DNN55/LightRequestHandler.ashx")

        'request.ExtensionID = New System.Guid("957E0662-2EAA-4C3F-8650-2605F6CCBAD1") ' EchoExtension
        request.ExtensionID = New System.Guid("343B0274-6481-49A0-A736-642370C57FC1") ' messaging


        While (Console.ReadKey().Key <> ConsoleKey.X)

            Console.WriteLine("--------------------------------------------------------------------------------------------------------going")

            Try
                response = p.SendRequest(request)
                If (response.Value = request.Args(0)) Then
                    Console.WriteLine("YOU DID IT!")
                    Console.WriteLine(p.LastCallDuration.TotalMilliseconds & "ms")
                End If

                If (request.MethodName = "GetMessageByID") Then
                    Dim msg As String = response.Value
                    Dim json As New System.Web.Script.Serialization.JavaScriptSerializer()
                    Dim sm As SimpleMessage = json.Deserialize(Of SimpleMessage)(response.Value)
                    Console.WriteLine("------------------------------------------------")
                    Console.WriteLine(String.Format("Message ID:{0} From:{1}, Subject:{2} at {3} Said:{4}", sm.ID, sm.FromUser, sm.Subject, sm.DateSent, sm.Body))
                    Console.WriteLine("------------------------------------------------")
                ElseIf (request.MethodName = "GetUserInbox") Then
                    Dim msg As String = response.Value
                    Dim json As New System.Web.Script.Serialization.JavaScriptSerializer()
                    Dim sm As List(Of SimpleMessage) = json.Deserialize(Of List(Of SimpleMessage))(response.Value)
                    Console.WriteLine(String.Format("MESSAGE COUNT:{0}", sm.Count))
                    For Each m As SimpleMessage In sm
                        Console.WriteLine("------------------------------------------------")
                        Console.WriteLine(String.Format("Message ID:{0} From:{1}, Subject:{2} at {3} Said:{4}", m.ID, m.FromUser, m.Subject, m.DateSent, m.Body))
                        Console.WriteLine("------------------------------------------------")
                    Next
                End If

                Console.WriteLine("done")
            Catch ex As Exception
                Console.WriteLine(ex.ToString())
            End Try


        End While

    End Sub

End Module
Public Class SimpleMessage
    Public ID As Integer
    Public Subject As String
    Public Body As String
    Public DateSent As DateTime
    Public FromUser As String

End Class

